<template>
  <div id="app">
    <!-- 头部 -->
    <van-nav-bar
      :title="title"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      fixed
    />
    <!-- 内容 -->
    <router-view></router-view>
    <!-- foolter -->
    <van-tabbar v-model="active">
      <van-tabbar-item icon="home-o" to="/home"></van-tabbar-item>
      <van-tabbar-item icon="friends-o" to="/friends"></van-tabbar-item>
      <van-tabbar-item icon="cart-o" to="/cart" badge="6"></van-tabbar-item>
      <van-tabbar-item icon="search" to="/search"></van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
export default {
  data: () => ({
    title: sessionStorage.title || 'home',
    active: Number(sessionStorage.active) || 0
  }),
  created() {
    // this.$router.push({ path: '/home' })
    // this.$router.replace({ path: '/home' })
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    }
  },
  watch: {
    '$route.meta'(meta) {
      this.title = meta.title
      this.active = meta.active
      sessionStorage.title = meta.title
      sessionStorage.active = meta.active
    }
  }
}
</script>
<style lang="less" scoped>
#app {
  padding-top: 46px;
  padding-bottom: 50px;
}
</style>
